package Written;

import java.util.Arrays;

public class KS_1 {
    /*
        n个人围成一圈，从1开始报数，每报到3的倍数剔除该人，循环至最后一人，那人序号多少
     */
    public int solve(int n) {
        int[] person = new int[n + 1];
        int count = 1;
        int out = 0;
        Arrays.fill(person, 1);
        for (int i = 1; i <= n; i++) {
            if (person[i] == 0) {
                if (i == n) i = 0;
                continue;
            }
            if (count == 3) {
                person[i] = 0;
                out++;
                count = 1;
            } else count++;
            if (i == n) i = 0;
            if (out == n - 1) break;
        }
        for (int i = 1; i <= n; i++) {
            if (person[i] == 1) return i;
        }
        return 0;
    }

    public static void main(String[] args) {
        KS_1 main = new KS_1();
        System.out.println(main.solve(100));
    }
}
